local base = _G
module("CLI.query_order")

function main(f)
	if f == "Query" then
		Query()
	--[[
	elseif then
	--]]
	end
end

function Query()
	base.io.write("Input order id please:")
	local id = base.io.read()
	local sm = base.require("Function.order_management")
	local t,c = sm.Query(id)
	base.io.write("\n========== Order ==========\n")
	if t == -1 then
		base.io.write("ERROR while querying order!Code:" .. c .. "\n")
	elseif t[1][1] == nil then
		base.io.write("No such order!\n")
	else
		base.io.write("OrderID:" .. (t[1][1] or "Unavailable") .. "\n")
		base.io.write("CustomerID:" .. (t[2][1] or "Unavailable") .. "\n")
		base.io.write("StockID:" .. (t[3][1] or "Unavailable") .. "\n")
		base.io.write("Amount:" .. (t[4][1] or "Unavailable") .. "\n")
		base.io.write("OrderDate:" .. (t[5][1] or "Unavailable") .. "\n")
		base.io.write("State:" .. (t[6][1] or "Unavailable") .. "\n")
	end
	base.io.write("\n")
end

function QueryForPendingOrder()
	local sm = base.require("Function.order_management")
	local t,c = sm.QueryForPendingOrder()
	base.io.write("\n========== Pending Order ==========\n")
	if t == -1 then
		base.io.write("ERROR while querying order!Code:" .. c .. "\n")
	elseif t[1][1] == nil then
		base.io.write("No such order!\n")
	else
		base.io.write("OrderID:" .. (t[1] or "Unavailable") .. "\n")
		base.io.write("OrderID:" .. (t[2] or "Unavailable") .. "\n")
		base.io.write("OrderID:" .. (t[3] or "Unavailable") .. "\n")
		base.io.write("OrderID:" .. (t[4] or "Unavailable") .. "\n")
		base.io.write("OrderID:" .. (t[5] or "Unavailable") .. "\n")
	end
	base.io.write("\n")
end